using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace Sipek
{
    public partial class frmCustomerActivity : Form
    {
        public frmCustomerActivity()
        {
            InitializeComponent();
        }

        private string sql;

        private void ConnectToData()
        {
            System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
        
            conn.ConnectionString = "DSN=kubikcrm";
            try
            {
                conn.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed To Connect");
            }
            finally
            {
                conn.Close();
            }
            sql = "SELECT DATE_FORMAT(activity_date,'%d-%m-%Y'),TIME_FORMAT(activity_time,'%h:%i:%s'),TIME_FORMAT(activity_time2,'%h:%i:%s'),activity_type,pic,activity_desc FROM activity_transaction JOIN activity ON activity.id=activity_transaction.activity_id WHERE activity_transaction.pic='SAM' ORDER BY activity_date DESC,activity_time DESC ";
            FillListView(conn, sql,lvData);
        }

        private void FillListView(OdbcConnection conn, String sql, ListView lv)
        {
            lv.Items.Clear();
            OdbcCommand cmdRead;
            OdbcDataReader datReader;
            string strField;
            strField = sql;
            cmdRead = new OdbcCommand(strField, conn);
            try
            {
                conn.Open();
                datReader = cmdRead.ExecuteReader();
                // fill ListView
                while (datReader.Read())
                {
                    ListViewItem objListItem = new ListViewItem(datReader.GetValue(0).ToString());
                    for (int c = 1; c < datReader.FieldCount; c++)
                    {
                        objListItem.SubItems.Add(datReader.GetValue(c).ToString());
                    }
                    objListItem.ImageIndex = 5;
                    lv.Items.Add(objListItem);
                }
                datReader.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed To Connect Table ! ");
            }
            finally
            {

                conn.Close();
            }

        }
        private void frmCustomerActivity_Load(object sender, EventArgs e)
        {
            this.Text = Properties.Settings.Default.CustomerName;
            ConnectToData();
        }

        
    }
}